package com.finddreams.module_gooddetail;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.finddreams.module_base.base.BaseActivity;
import com.finddreams.module_base.event.LoginStateEvent;
import com.finddreams.module_base.utils.ModuleRouteService;
import com.finddreams.module_base.utils.RouteUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liuxiang on 2017/10/24.
 */
@Route(path = RouteUtils.GoodDetail_Activity_Main)
public class GoodDetailActivity extends BaseActivity {
    TextView tvGoodName;
    TextView tv_address;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gooddetail_activity_main);
        tvGoodName=findViewById(R.id.tv_good_name);
        tv_address=findViewById(R.id.tv_address);
        initData();
        setTitle("商品详情模块");

    }

    private void initData() {
        Intent intent = getIntent();
        String goodName = intent.getStringExtra("goodName");
        tvGoodName.setText(goodName);
        if (LoginStateEvent.getInstance().isSuccess()) {
            tv_address.setText("用户所在地址:" + ModuleRouteService.getUserAddress("123"));//RouteUtils.getUserAddress("123")
        }else{
            Toast.makeText(this,"未登录，跳转登录",Toast.LENGTH_SHORT).show();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    RouteUtils.startLoginActivity();
                }
            },1000);
        }
    }

    @Subscribe (threadMode = ThreadMode.MAIN)
    public void loginSuccess(LoginStateEvent event){
        if (event.isSuccess){
            tv_address.setText("用户所在地址:" + RouteUtils.getUserAddress("123"));//RouteUtils.getUserAddress("123")
        }else{
            tv_address.setText("用户所在地址:未登录" );//RouteUtils.getUserAddress("123")
        }
    }
}
